home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Waves / Make Sample Data < prev    next >
Text File  |  1996-01-29  |  28KB  |  808 lines

  1. #pragma rtGlobals=1
  2.  
  3. // HR, 12/95. Updated and revised for Igor Pro 3.0.
  4. //        Used rtGlobals and data folders to store globals.
  5. //        Changed all macros into functions. Then added dialog routines (e.g., MakeSamplePeriodicDialog).
  6.  
  7. Function/S SetMakeSampleDataFolderCurrent()    // Returns previous current data folder.
  8.     String dfSav = GetDataFolder(1)
  9.  
  10.     NewDataFolder/O/S root:Packages                // Put our data folder in standard packages data folder.
  11.     NewDataFolder/O/S :'Make Sample Data'
  12.     return dfSav
  13. End
  14.  
  15. Function MakeSampleDataGeneralGlobals()
  16.     String dfSav = SetMakeSampleDataFolderCurrent()
  17.     if (exists("gNumPoints") == 0)
  18.         Variable/G gNumPoints = 500
  19.         Variable/G gXMin = 0
  20.         Variable/G gXMax = 6
  21.         Variable/G gPercentXNoise = 0
  22.         Variable/G gPercentYNoise = 0
  23.         Variable/G gAutoDisplay = 1        
  24.     endif
  25.     SetDataFolder dfSav
  26. End
  27.  
  28. Function SetSampleDataSettings(numPoints, xMin, xMax, percentXNoise, percentYNoise, autoDisplay)
  29.     Variable numPoints                        // Number of points in output waves
  30.     Variable xMin
  31.     Variable xMax
  32.     Variable percentXNoise
  33.     Variable percentYNoise
  34.     Variable autoDisplay                        // 1 = yes, 2 = no
  35.  
  36.     String dfSav = SetMakeSampleDataFolderCurrent()
  37.     
  38.     MakeSampleDataGeneralGlobals()
  39.     Variable/G gNumPoints, gXMin, gXMax, gPercentXNoise, gPercentYNoise, gAutoDisplay    // This just creates NVAR references. The variables were created above.
  40.     
  41.     gNumPoints = numPoints
  42.     gXMin = xMin
  43.     gXMax = xMax
  44.     gPercentXNoise = percentXNoise
  45.     gPercentYNoise = percentYNoise
  46.     gAutoDisplay = autoDisplay==1
  47.     
  48.     SetDataFolder dfSav
  49. End
  50.  
  51. Proc SetSampleDataSettingsDialog(numPoints, xMin, xMax, percentXNoise, percentYNoise, autoDisplay)
  52.     Variable numPoints = NumVarOrDefault("root:Packages:Make Sample Data:gNumPoints", 500)
  53.     Prompt numPoints, "Number of points in output waves"
  54.     Variable xMin = NumVarOrDefault("root:Packages:Make Sample Data:gXMin", 0)
  55.     Variable xMax = NumVarOrDefault("root:Packages:Make Sample Data:gXMax", 6)
  56.     Variable percentXNoise = NumVarOrDefault("root:Packages:Make Sample Data:gPercentXNoise", 0)
  57.     Prompt percentXNoise, "Percent X Noise"
  58.     Variable percentYNoise = NumVarOrDefault("root:Packages:Make Sample Data:gPercentYNoise", 0)
  59.     Prompt percentYNoise, "Percent Y Noise"
  60.     Variable autoDisplay
  61.     Prompt autoDisplay, "Auto-display output", popup "Yes;No"
  62.     
  63.     Silent 1
  64.     SetSampleDataSettings(numPoints, xMin, xMax, percentXNoise, percentYNoise, autoDisplay)
  65. End
  66.  
  67. Function MakeSampleDataWaves(xWave, yWave, numPoints, parameterWave)
  68.     String xWave                // name of x wave or "" if waveform data
  69.     String yWave
  70.     Variable numPoints
  71.     Wave parameterWave
  72.     
  73.     PauseUpdate; Silent 1
  74.     
  75.     Variable xMin = parameterWave[0]
  76.     Variable xMax = parameterWave[1]
  77.     Variable offset = parameterWave[2]
  78.     Variable amplitude = parameterWave[3]
  79.     Variable percentXNoise = parameterWave[4]
  80.     Variable percentYNoise = parameterWave[5]
  81.     
  82.     Variable xNoise = amplitude * percentXNoise / 100
  83.     Variable yNoise = amplitude * percentYNoise / 100
  84.     
  85.     Variable isXY = strlen(xWave) > 0
  86.     
  87.     Make/O/N=(numPoints) $yWave
  88.     Wave yw = $yWave
  89.  
  90.     if (isXY)
  91.         Make/O/N=(numPoints) $xWave
  92.         Wave xw = $xWave
  93.         SetScale/P x 0, 1, xw, yw
  94.         xw = xMin + (xMax - xMin) * p / (numPoints -1)
  95.         if (xNoise)
  96.             xw += gnoise(xNoise)
  97.         endif
  98.     else
  99.         SetScale/I x xMin, xMax, yw
  100.     endif
  101.     
  102.     yw = offset + gnoise(yNoise)
  103. End
  104.  
  105. Function/S MakeSampleTempWave(which, xWave, yWave)
  106.     Variable which                // 1 = x, 2 = y
  107.     String xWave                    // name of x output wave or "" if none
  108.     String yWave                    // name of y output wave
  109.     
  110.     Variable isXY = strlen(xWave) > 0
  111.     String xTempWaveName, yTempWaveName
  112.     
  113.     if (which == 1)
  114.         if (isXY)
  115.             xTempWaveName = "xSampleDataTemp"
  116.             Duplicate/O $xWave, $xTempWaveName
  117.         else
  118.             xTempWaveName = ""
  119.         endif
  120.         return xTempWaveName
  121.     endif
  122.     
  123.     if (which == 2)
  124.         yTempWaveName = "ySampleDataTemp"
  125.         Duplicate/O $yWave, $yTempWaveName
  126.         return yTempWaveName
  127.     endif
  128. End
  129.  
  130. Function FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  131.     Variable mode                    // 1 = Set Output Wave, 2 = Add to Output Wave, 3 = Multiply Output Wave
  132.     String xWave                    // name of x output wave or "" if none
  133.     String yWave                    // name of y output wave
  134.     String xTempWaveName        // name of wave containing new x data or "" if none
  135.     String yTempWaveName        // name of wave containing new y data
  136.     
  137.     Variable isXY = strlen(xWave) > 0
  138.  
  139.     Wave ytw = $yTempWaveName
  140.     Wave xtw = $xTempWaveName
  141.  
  142.     if (mode == 1)                                    // setting output wave?
  143.         Duplicate/O ytw, $yWave
  144.         if (isXY)
  145.             Duplicate/O xtw, $xWave
  146.         endif
  147.     endif
  148.     
  149.     Wave yw = $yWave
  150.     
  151.     if (mode == 2)                                    // adding to output wave?
  152.         if (isXY)
  153.             yw += ytw
  154.         else
  155.             yw += ytw
  156.         endif
  157.     endif
  158.     
  159.     if (mode == 3)                                    // multiplying output wave?
  160.         if (isXY)
  161.             yw *= ytw
  162.         else
  163.             yw *= ytw
  164.         endif
  165.     endif
  166.  
  167.     KillWaves/Z ytw
  168.     if (isXY)
  169.         KillWaves/Z xtw
  170.     endif
  171. End
  172.  
  173. Function CheckMakeSampleDataDisplay(xWave, yWave)
  174.     String xWave, yWave
  175.     
  176.     MakeSampleDataGeneralGlobals()
  177.     
  178.     Variable isXY = strlen(xWave) > 0
  179.     String topGraphName = WinName(0, 1)                    // "" if no graphs
  180.     Variable waveIsDisplayed
  181.  
  182.     NVAR gAutoDisplay = root:Packages:'Make Sample Data':gAutoDisplay
  183.     if (gAutoDisplay == 1)                                    // want to make sure new waves are displayed ?
  184.         waveIsDisplayed = 0
  185.         if (strlen(topGraphName))
  186.             CheckDisplayed/W=$topGraphName $yWave
  187.             waveIsDisplayed = V_flag
  188.         endif
  189.         if (waveIsDisplayed == 0)                            // wave not displayed in top graph?
  190.             if (strlen(topGraphName) == 0)                // no graph?
  191.                 Display as "Make Sample Data Graph"        // make a new graph
  192.             endif
  193.             if (isXY)
  194.                 AppendToGraph $yWave vs $xWave
  195.             else
  196.                 AppendToGraph $yWave
  197.             endif
  198.         endif
  199.     endif
  200. End
  201.  
  202. Function/S MakeSampleModePrompt()
  203.     String s
  204.  
  205.     MakeSampleDataGeneralGlobals()
  206.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  207.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  208.     
  209.     sprintf s, "Mode (xMin=%.4g, xMax=%.4g)\r" gXMin, gXMax
  210.     return s
  211. End
  212.  
  213. // MakeSampleDataCheckWaves(proposedXWaveName, proposedYWaveName)
  214. //    proposedXWaveName is "_none_", "_new_" or a name of a wave which may or may not exist.
  215. //    proposedYWaveName is "_new_" or a name of a wave which may or may not exist.
  216. //    
  217. //    This routine generates wave names if the proposed name is "_new_".
  218. //    It then makes the wave or waves if they do not already exist.
  219. //
  220. //    It returns the names as a semicolon-separated string. For example: "xData0;yData0".
  221. //    The x wave name may be zero-length. There is no semicolon at the end.
  222. Function/S MakeSampleDataCheckWaves(proposedXWaveName, proposedYWaveName)
  223.     String proposedXWaveName, proposedYWaveName
  224.  
  225.     MakeSampleDataGeneralGlobals()
  226.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  227.     
  228.     Variable i
  229.     String xBase, xWave, yBase, yWave
  230.     Variable needNewXWaveName, needNewYWaveName
  231.  
  232.     needNewXWaveName = CmpStr(proposedXWaveName, "_new_") == 0
  233.     needNewYWaveName = CmpStr(proposedYWaveName, "_new_") == 0
  234.     xWave = proposedXWaveName
  235.     yWave = proposedYWaveName
  236.     xBase = "xData"
  237.     yBase = "yData"
  238.     
  239.     if (CmpStr(proposedXWaveName, "_none_") == 0)
  240.         xWave = ""
  241.     endif
  242.     if (needNewXWaveName)
  243.         i = 0
  244.         do
  245.             xWave = xBase + num2istr(i)
  246.             if (exists(xWave) == 0)                                    // x name is free but check
  247.                 if (needNewYWaveName == 0)                        // NOT making XY pair ?
  248.                     break                                                // we're done
  249.                 endif
  250.                 // Here if making XY pair. We want the appended digit to be the same for X and Y.
  251.                 yWave = yBase + num2istr(i)
  252.                 if (exists(yWave) == 0)                                // is yData<nnn> free also
  253.                     needNewYWaveName = 0                            // so that we don't try to make another y wave below
  254.                     break                                                // we're done
  255.                 endif
  256.             endif
  257.             i += 1
  258.         while (1)
  259.     endif
  260.  
  261.     if (needNewYWaveName)
  262.         i = 0
  263.         do
  264.             yWave = yBase + num2istr(i)
  265.             if (exists(yWave) == 0)                                    // y name is free ?
  266.                 break                                                    // yes, we're done
  267.             endif
  268.             i += 1
  269.         while (1)
  270.     endif
  271.  
  272.     // At this point we have generated wave names, if necessary. Now make the waves.
  273.     
  274.     if (strlen(xWave) > 0)                            // x wave needed ?
  275.         if (exists(xWave) == 0)                        // need to make it ?
  276.             Make/N=(gNumPoints) $xWave
  277.             Printf "Created new X wave: %s\r", xWave
  278.         endif
  279.     endif
  280.     
  281.     if ((exists(yWave) == 0))                        // need to make it ?
  282.         Make/N=(gNumPoints) $yWave
  283.         Printf "Created new Y wave: %s\r", yWave
  284.     endif
  285.  
  286.     return xWave + ";" + yWave                        // e.g. "xData0;yData0"
  287. End
  288.  
  289. Function FMakeSampleTriangle(x)        // x goes from 0 to 1
  290.     Variable x
  291.     
  292.     if (x < .5)
  293.         return 2*x
  294.     else
  295.         return 2*(1 - x)
  296.     endif
  297. End
  298.  
  299. Function SetSamplePeriodicGlobals(type, offset, amplitude, phase, cycles)
  300.     Variable type, offset, amplitude, phase, cycles
  301.     
  302.     String dfSav = SetMakeSampleDataFolderCurrent()
  303.     if (exists("gPeriodicType") == 0)
  304.         Variable/G gPeriodicType = type
  305.         Variable/G gPeriodicOffset = offset
  306.         Variable/G gPeriodicAmplitude = amplitude
  307.         Variable/G gPeriodicPhase = phase
  308.         Variable/G gPeriodicCycles = cycles
  309.     endif
  310.     SetDataFolder dfSav
  311. End
  312.  
  313. Function MakeSamplePeriodic(xWave, yWave, mode, type, offset, amplitude, phase, cycles)
  314.     String xWave                    // name of x wave, "_none_" or "_new_"
  315.     String yWave                    // name of y wave or "_new_"
  316.     Variable mode                    // 1 = set output wave, 2 = add to output wave, 3 = multiply with output wave
  317.     Variable type                    // 1 = sine, 2 = square wave, 3 = triangle wave, 4 = sawtooth
  318.     Variable offset                    // DC offset
  319.     Variable amplitude            // signal amplitude
  320.     Variable phase                    // phase in degrees
  321.     Variable cycles                // number of cycles
  322.     
  323.     // Save settings for next time
  324.     SetSamplePeriodicGlobals(type, offset, amplitude, phase, cycles)
  325.     
  326.     MakeSampleDataGeneralGlobals()
  327.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  328.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  329.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  330.     NVAR gPercentXNoise = root:Packages:'Make Sample Data':gPercentXNoise
  331.     NVAR gPercentYNoise = root:Packages:'Make Sample Data':gPercentYNoise
  332.     
  333.     Variable isXY
  334.     String xTempWaveName, yTempWaveName
  335.     Variable omega
  336.     
  337.     String temp = MakeSampleDataCheckWaves(xWave, yWave)    // returns, for example, "xData0;yData0"
  338.     Variable pos = strsearch(temp,";",0)            // Find semicolon between x and y wave names
  339.     xWave = temp[0, pos-1]                            // Extract x wave name
  340.     yWave = temp[pos+1, strlen(temp)]            // Extract y wave name
  341.     isXY = strlen(xWave) > 0
  342.  
  343.     phase = phase*PI/180                        // convert to radians
  344.     omega = 2*PI*cycles / (gXMax - gXMin)
  345.     omega *= (gNumPoints-1) / gNumPoints        // one cycle goes up to but not including start of next cycle
  346.     
  347.     xTempWaveName = MakeSampleTempWave(1, xWave, yWave)
  348.     yTempWaveName = MakeSampleTempWave(2, xWave, yWave)
  349.     
  350.     Make/O/N=6 pwMakeSampleData            // parameter wave for MakeSampleData
  351.     pwMakeSampleData[0] = gXMin
  352.     pwMakeSampleData[1] = gXMax
  353.     pwMakeSampleData[2] = offset
  354.     pwMakeSampleData[3] = amplitude
  355.     pwMakeSampleData[4] = gPercentXNoise
  356.     pwMakeSampleData[5] = gPercentYNoise
  357.     MakeSampleDataWaves(xTempWaveName, yTempWaveName, gNumPoints, pwMakeSampleData)
  358.     KillWaves/Z pwMakeSampleData
  359.  
  360.     Wave ytw = $yTempWaveName
  361.     Wave xtw = $xTempWaveName
  362.     
  363.     if (type == 1)            // sine ?
  364.         if (isXY)
  365.             ytw += amplitude*sin(phase + omega*xtw)
  366.         else
  367.             ytw += amplitude*sin(phase +  omega*x)
  368.         endif
  369.     endif
  370.     
  371.     if (type == 2)            // square wave ?
  372.         if (isXY)
  373.             ytw += amplitude*(sawtooth(phase + omega*xtw) < .5)
  374.         else
  375.             ytw += amplitude*(sawtooth(phase +  omega*x) < .5)
  376.         endif
  377.     endif
  378.     
  379.     if (type == 3)            // Triangle wave ?
  380.         if (isXY)
  381.             ytw += amplitude*(FMakeSampleTriangle(sawtooth(phase + omega*xtw)))
  382.         else
  383.             ytw += amplitude*(FMakeSampleTriangle(sawtooth(phase +  omega*x)))
  384.         endif
  385.     endif
  386.     
  387.     if (type == 4)            // sawtooth wave ?
  388.         if (isXY)
  389.             ytw += amplitude*sawtooth(phase + omega*xtw)
  390.         else
  391.             ytw += amplitude*sawtooth(phase +  omega*x)
  392.         endif
  393.     endif
  394.  
  395.     FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  396.     CheckMakeSampleDataDisplay(xWave, yWave)        // display new data if desired
  397. End
  398.  
  399. Proc MakeSamplePeriodicDialog(xWave, yWave, mode, type, offset, amplitude, phase, cycles)
  400.     String xWave                    // name of x wave or "" if waveform data
  401.     Prompt xWave, "X Wave", popup "_none_;_new_;" + WaveList("*", ";", "")
  402.     String yWave
  403.     Prompt yWave, "Y Wave", popup "_new_;" + WaveList("*", ";", "")
  404.     Variable mode = 1
  405.     Prompt mode, MakeSampleModePrompt(), popup "Set Output Wave;Add to Output Wave;Multiply Output Wave"
  406.     Variable type = NumVarOrDefault("root:Packages:'Make Sample Data':gPeriodicType", 1)
  407.     Prompt type, "Type", popup "Sine;Square;Triangle;Sawtooth"
  408.     Variable offset = NumVarOrDefault("root:Packages:'Make Sample Data':gPeriodicOffset", 0)
  409.     Prompt offset, "Offset"
  410.     Variable amplitude = NumVarOrDefault("root:Packages:'Make Sample Data':gPeriodicAmplitude", 1)
  411.     Prompt amplitude, "Amplitude"
  412.     Variable phase = NumVarOrDefault("root:Packages:'Make Sample Data':gPeriodicPhase", 0)
  413.     Prompt phase, "Phase in Degrees"
  414.     Variable cycles = NumVarOrDefault("root:Packages:'Make Sample Data':gPeriodicCycles", 1)
  415.     Prompt cycles, "Cycles"
  416.  
  417.     PauseUpdate; Silent 1
  418.  
  419.     MakeSamplePeriodic(xWave, yWave, mode, type, offset, amplitude, phase, cycles)
  420. End
  421.  
  422. Function FMakeSamplePulse(x, pulseStart, pulseEnd)        // all in radians
  423.     Variable x
  424.     Variable pulseStart
  425.     Variable pulseEnd
  426.     
  427.     if (x < 0)
  428.         x = 2*PI + mod(x, 2*PI)        // convert negative phase to equivalent positive
  429.     endif
  430.     x = mod(abs(x), 2*PI)
  431.     if ((x >= pulseStart) %& (x < pulseEnd))
  432.         return 1
  433.     else
  434.         return 0
  435.     endif
  436. End
  437.  
  438. Function SetSamplePulseGlobals(offset, amplitude, phase, cycles, widthInDegrees)
  439.     Variable offset, amplitude, phase, cycles, widthInDegrees
  440.     
  441.     String dfSav = SetMakeSampleDataFolderCurrent()
  442.     if (exists("gPulseOffset") == 0)
  443.         Variable/G gPulseOffset = offset
  444.         Variable/G gPulseAmplitude = amplitude
  445.         Variable/G gPulsePhase = phase
  446.         Variable/G gPulseCycles = cycles
  447.         Variable/G gPulseWidthInDegrees = widthInDegrees
  448.     endif
  449.     SetDataFolder dfSav
  450. End
  451.  
  452. Function MakeSamplePulse(xWave, yWave, mode, offset, amplitude, phase, cycles, widthInDegrees)
  453.     String xWave                    // name of x wave, "_none_" or "_new_"
  454.     String yWave                    // name of y wave or "_new_"
  455.     Variable mode                    // 1 = set output wave, 2 = add to output wave, 3 = multiply with output wave
  456.     Variable offset                    // DC offset
  457.     Variable amplitude            // signal amplitude
  458.     Variable phase                    // phase in degrees
  459.     Variable cycles                // number of cycles
  460.     Variable widthInDegrees        // pulse width
  461.     
  462.     // Save settings for next time
  463.     SetSamplePulseGlobals(offset, amplitude, phase, cycles, widthInDegrees)
  464.     
  465.     MakeSampleDataGeneralGlobals()
  466.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  467.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  468.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  469.     NVAR gPercentXNoise = root:Packages:'Make Sample Data':gPercentXNoise
  470.     NVAR gPercentYNoise = root:Packages:'Make Sample Data':gPercentYNoise
  471.     
  472.     Variable isXY
  473.     String xTempWaveName, yTempWaveName
  474.     Variable omega, pulseStart, pulseEnd
  475.     
  476.     String temp = MakeSampleDataCheckWaves(xWave, yWave)    // returns, for example, "xData0;yData0"
  477.     Variable pos = strsearch(temp,";",0)            // Find semicolon between x and y wave names
  478.     xWave = temp[0, pos-1]                            // Extract x wave name
  479.     yWave = temp[pos+1, strlen(temp)]            // Extract y wave name
  480.     isXY = strlen(xWave) > 0
  481.  
  482.     phase = phase*PI/180                        // convert to radians
  483.     omega = 2*PI*cycles / (gXMax - gXMin)
  484.     omega *= (gNumPoints-1) / gNumPoints    // one cycle goes up to but not including start of next cycle
  485.     pulseStart = 0
  486.     pulseEnd = widthInDegrees*PI/180            // convert to radians
  487.     
  488.     xTempWaveName = MakeSampleTempWave(1, xWave, yWave)
  489.     yTempWaveName = MakeSampleTempWave(2, xWave, yWave)
  490.     
  491.     Make/O/N=6 pwMakeSampleData            // parameter wave for MakeSampleData
  492.     pwMakeSampleData[0] = gXMin
  493.     pwMakeSampleData[1] = gXMax
  494.     pwMakeSampleData[2] = offset
  495.     pwMakeSampleData[3] = amplitude
  496.     pwMakeSampleData[4] = gPercentXNoise
  497.     pwMakeSampleData[5] = gPercentYNoise
  498.     MakeSampleDataWaves(xTempWaveName, yTempWaveName, gNumPoints, pwMakeSampleData)
  499.     KillWaves/Z pwMakeSampleData
  500.     
  501.     Wave ytw = $yTempWaveName
  502.     Wave xtw = $xTempWaveName
  503.  
  504.     if (isXY)
  505.         ytw += amplitude*(FMakeSamplePulse(phase + omega*xtw, pulseStart, pulseEnd))
  506.     else
  507.         ytw += amplitude*(FMakeSamplePulse(phase +  omega*x, pulseStart, pulseEnd))
  508.     endif
  509.  
  510.     FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  511.     CheckMakeSampleDataDisplay(xWave, yWave)        // display new data if desired
  512. End
  513.  
  514. Proc MakeSamplePulseDialog(xWave, yWave, mode, offset, amplitude, phase, cycles, widthInDegrees)
  515.     String xWave                    // name of x wave or "" if waveform data
  516.     Prompt xWave, "X Wave", popup "_none_;_new_;" + WaveList("*", ";", "")
  517.     String yWave
  518.     Prompt yWave, "Y Wave", popup "_new_;" + WaveList("*", ";", "")
  519.     Variable mode = 1
  520.     Prompt mode, MakeSampleModePrompt(), popup "Set Output Wave;Add to Output Wave;Multiply Output Wave"
  521.     Variable offset = NumVarOrDefault("root:Packages:'Make Sample Data':gPulseOffset", 0)
  522.     Prompt offset, "Offset"
  523.     Variable amplitude = NumVarOrDefault("root:Packages:'Make Sample Data':gPulseAmplitude", 1)
  524.     Prompt amplitude, "Amplitude"
  525.     Variable phase = NumVarOrDefault("root:Packages:'Make Sample Data':gPulsePhase", 0)
  526.     Prompt phase, "Phase in Degrees"
  527.     Variable cycles = NumVarOrDefault("root:Packages:'Make Sample Data':gPulseCycles", 1)
  528.     Prompt cycles, "Cycles"
  529.     Variable widthInDegrees = NumVarOrDefault("root:Packages:'Make Sample Data':gPulseWidthInDegrees", 30)
  530.     Prompt widthInDegrees, "Width in Degrees"
  531.     
  532.     PauseUpdate; Silent 1
  533.     MakeSamplePulse(xWave, yWave, mode, offset, amplitude, phase, cycles, widthInDegrees)
  534. End
  535.  
  536. Function SetSampleExpGlobals(offset, amplitude, timeConstant)
  537.     Variable offset, amplitude, timeConstant
  538.     
  539.     String dfSav = SetMakeSampleDataFolderCurrent()
  540.     if (exists("gExpOffset") == 0)
  541.         Variable/G gExpOffset = offset
  542.         Variable/G gExpAmplitude = amplitude
  543.         Variable/G gExpTimeConstant = timeConstant
  544.     endif
  545.     SetDataFolder dfSav
  546. End
  547.  
  548. Function MakeSampleExponential(xWave, yWave, mode, offset, amplitude, timeConstant)
  549.     String xWave                    // name of x wave, "_none_" or "_new_"
  550.     String yWave                    // name of y wave or "_new_"
  551.     Variable mode                    // 1 = set output wave, 2 = add to output wave, 3 = multiply with output wave
  552.     Variable offset                    // DC offset
  553.     Variable amplitude            // signal amplitude
  554.     Variable timeConstant            // time constant in seconds
  555.  
  556.     // Save settings for next time
  557.     SetSampleExpGlobals(offset, amplitude, timeConstant)
  558.     
  559.     MakeSampleDataGeneralGlobals()
  560.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  561.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  562.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  563.     NVAR gPercentXNoise = root:Packages:'Make Sample Data':gPercentXNoise
  564.     NVAR gPercentYNoise = root:Packages:'Make Sample Data':gPercentYNoise
  565.     
  566.     Variable isXY
  567.     String xTempWaveName, yTempWaveName
  568.     
  569.     String temp = MakeSampleDataCheckWaves(xWave, yWave)    // returns, for example, "xData0;yData0"
  570.     Variable pos = strsearch(temp,";",0)            // Find semicolon between x and y wave names
  571.     xWave = temp[0, pos-1]                            // Extract x wave name
  572.     yWave = temp[pos+1, strlen(temp)]            // Extract y wave name
  573.     isXY = strlen(xWave) > 0
  574.     
  575.     xTempWaveName = MakeSampleTempWave(1, xWave, yWave)
  576.     yTempWaveName = MakeSampleTempWave(2, xWave, yWave)
  577.     
  578.     Make/O/N=6 pwMakeSampleData            // parameter wave for MakeSampleData
  579.     pwMakeSampleData[0] = gXMin
  580.     pwMakeSampleData[1] = gXMax
  581.     pwMakeSampleData[2] = offset
  582.     pwMakeSampleData[3] = amplitude
  583.     pwMakeSampleData[4] = gPercentXNoise
  584.     pwMakeSampleData[5] = gPercentYNoise
  585.     MakeSampleDataWaves(xTempWaveName, yTempWaveName, gNumPoints, pwMakeSampleData)
  586.     KillWaves/Z pwMakeSampleData
  587.  
  588.     Wave ytw = $yTempWaveName
  589.     Wave xtw = $xTempWaveName
  590.     
  591.     if (isXY)
  592.         ytw += amplitude*exp(-xtw/timeConstant)
  593.     else
  594.         ytw += amplitude*exp(-x/timeConstant)
  595.     endif
  596.  
  597.     FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  598.     CheckMakeSampleDataDisplay(xWave, yWave)        // display new data if desired
  599. End
  600.  
  601. Proc MakeSampleExponentialDialog(xWave, yWave, mode, offset, amplitude, timeConstant)
  602.     String xWave                    // name of x wave or "" if waveform data
  603.     Prompt xWave, "X Wave", popup "_none_;_new_;" + WaveList("*", ";", "")
  604.     String yWave
  605.     Prompt yWave, "Y Wave", popup "_new_;" + WaveList("*", ";", "")
  606.     Variable mode = 1
  607.     Prompt mode, MakeSampleModePrompt(), popup "Set Output Wave;Add to Output Wave;Multiply Output Wave"
  608.     Variable offset = NumVarOrDefault("root:Packages:'Make Sample Data':gExpOffset", 0)
  609.     Prompt offset, "Offset"
  610.     Variable amplitude = NumVarOrDefault("root:Packages:'Make Sample Data':gExpAmplitude", 1)
  611.     Prompt amplitude, "Amplitude"
  612.     Variable timeConstant = NumVarOrDefault("root:Packages:'Make Sample Data':gExpTimeConstant", 1)
  613.     Prompt timeConstant, "Time constant"
  614.  
  615.     PauseUpdate; Silent 1
  616.     MakeSampleExponential(xWave, yWave, mode, offset, amplitude, timeConstant)
  617. End
  618.  
  619. Function SetSampleGaussianGlobals(offset, amplitude, xCenter, FWHM)
  620.     Variable offset, amplitude, xCenter, FWHM
  621.     
  622.     String dfSav = SetMakeSampleDataFolderCurrent()
  623.     if (exists("gGaussOffset") == 0)
  624.         Variable/G gGaussOffset = offset
  625.         Variable/G gGaussAmplitude = amplitude
  626.         Variable/G gGaussXCenter = xCenter
  627.         Variable/G gGaussFWHM = FWHM
  628.     endif
  629.     SetDataFolder dfSav
  630. End
  631.  
  632. Function MakeSampleGaussian(xWave, yWave, mode, offset, amplitude, xCenter, fwhm)
  633.     String xWave                    // name of x wave, "_none_" or "_new_"
  634.     String yWave                    // name of y wave or "_new_"
  635.     Variable mode                    // 1 = set output wave, 2 = add to output wave, 3 = multiply with output wave
  636.     Variable offset                    // DC offset
  637.     Variable amplitude            // signal amplitude
  638.     Variable xCenter                // center of Gaussian in x dimension
  639.     Variable fwhm                    // full width at half max
  640.     
  641.     // Save settings for next time
  642.     SetSampleGaussianGlobals(offset, amplitude, xCenter, FWHM)
  643.     
  644.     MakeSampleDataGeneralGlobals()
  645.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  646.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  647.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  648.     NVAR gPercentXNoise = root:Packages:'Make Sample Data':gPercentXNoise
  649.     NVAR gPercentYNoise = root:Packages:'Make Sample Data':gPercentYNoise
  650.     
  651.     Variable isXY
  652.     String xTempWaveName, yTempWaveName
  653.     Variable lk3
  654.     
  655.     String temp = MakeSampleDataCheckWaves(xWave, yWave)    // returns, for example, "xData0;yData0"
  656.     Variable pos = strsearch(temp,";",0)            // Find semicolon between x and y wave names
  657.     xWave = temp[0, pos-1]                            // Extract x wave name
  658.     yWave = temp[pos+1, strlen(temp)]            // Extract y wave name
  659.     isXY = strlen(xWave) > 0
  660.     
  661.     xTempWaveName = MakeSampleTempWave(1, xWave, yWave)
  662.     yTempWaveName = MakeSampleTempWave(2, xWave, yWave)
  663.     
  664.     Make/O/N=6 pwMakeSampleData            // parameter wave for MakeSampleData
  665.     pwMakeSampleData[0] = gXMin
  666.     pwMakeSampleData[1] = gXMax
  667.     pwMakeSampleData[2] = offset
  668.     pwMakeSampleData[3] = amplitude
  669.     pwMakeSampleData[4] = gPercentXNoise
  670.     pwMakeSampleData[5] = gPercentYNoise
  671.     MakeSampleDataWaves(xTempWaveName, yTempWaveName, gNumPoints, pwMakeSampleData)
  672.     KillWaves/Z pwMakeSampleData
  673.     
  674.     Wave ytw = $yTempWaveName
  675.     Wave xtw = $xTempWaveName
  676.  
  677.     lk3 = fwhm / (2 * sqrt(ln(2)))        // K3 in Gaussian formula
  678.     if (isXY)
  679.         ytw += amplitude*exp(-((xtw-xCenter)/lk3)^2)
  680.     else
  681.         ytw += amplitude*exp(-((x-xCenter)/lk3)^2)
  682.     endif
  683.  
  684.     FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  685.     CheckMakeSampleDataDisplay(xWave, yWave)        // display new data if desired
  686. End
  687.  
  688. Proc MakeSampleGaussianDialog(xWave, yWave, mode, offset, amplitude, xCenter, fwhm)
  689.     String xWave                    // name of x wave or "" if waveform data
  690.     Prompt xWave, "X Wave", popup "_none_;_new_;" + WaveList("*", ";", "")
  691.     String yWave
  692.     Prompt yWave, "Y Wave", popup "_new_;" + WaveList("*", ";", "")
  693.     Variable mode = 1
  694.     Prompt mode, MakeSampleModePrompt(), popup "Set Output Wave;Add to Output Wave;Multiply Output Wave"
  695.     Variable offset = NumVarOrDefault("root:Packages:'Make Sample Data':gGaussOffset", 0)
  696.     Prompt offset, "Offset"
  697.     Variable amplitude = NumVarOrDefault("root:Packages:'Make Sample Data':gGaussAmplitude", 1)
  698.     Prompt amplitude, "Amplitude"
  699.     Variable xCenter = NumVarOrDefault("root:Packages:'Make Sample Data':gGaussXCenter", 3)
  700.     Prompt xCenter, "X Center"
  701.     Variable fwhm = NumVarOrDefault("root:Packages:'Make Sample Data':gGaussFWHM", 1)
  702.     Prompt fwhm, "Full Width at Half Max"
  703.  
  704.     PauseUpdate; Silent 1
  705.     MakeSampleGaussian(xWave, yWave, mode, offset, amplitude, xCenter, fwhm)
  706. End
  707.  
  708. Function SetSampleNoiseGlobals(offset, amplitude, type, whichWave)
  709.     Variable offset, amplitude, type, whichWave
  710.     
  711.     String dfSav = SetMakeSampleDataFolderCurrent()
  712.     if (exists("gNoiseOffset") == 0)
  713.         Variable/G gNoiseOffset = offset
  714.         Variable/G gNoiseAmplitude = amplitude
  715.         Variable/G gNoiseType = type
  716.         Variable/G gNoiseWhichWave = whichWave
  717.     endif
  718.     SetDataFolder dfSav
  719. End
  720.  
  721. Function MakeSampleNoise(xWave, yWave, mode, offset, amplitude, type, whichWave)
  722.     String xWave                    // name of x wave, "_none_" or "_new_"
  723.     String yWave                    // name of y wave or "_new_"
  724.     Variable mode                    // 1 = set output wave, 2 = add to output wave, 3 = multiply with output wave
  725.     Variable offset                    // DC offset
  726.     Variable amplitude            // signal amplitude
  727.     Variable type                    // 1 = normal, 2 = even
  728.     Variable whichWave            // 1 = add noise to x wave, 2 = add noise to y wave, 3 = add to both
  729.     
  730.     // Save settings for next time
  731.     SetSampleNoiseGlobals(offset, amplitude, type, whichWave)
  732.     
  733.     MakeSampleDataGeneralGlobals()
  734.     NVAR gNumPoints = root:Packages:'Make Sample Data':gNumPoints
  735.     NVAR gXMin = root:Packages:'Make Sample Data':gXMin
  736.     NVAR gXMax = root:Packages:'Make Sample Data':gXMax
  737.     NVAR gPercentXNoise = root:Packages:'Make Sample Data':gPercentXNoise
  738.     NVAR gPercentYNoise = root:Packages:'Make Sample Data':gPercentYNoise
  739.     
  740.     Variable isXY
  741.     String xTempWaveName, yTempWaveName
  742.     
  743.     String temp = MakeSampleDataCheckWaves(xWave, yWave)    // returns, for example, "xData0;yData0"
  744.     Variable pos = strsearch(temp,";",0)            // Find semicolon between x and y wave names
  745.     xWave = temp[0, pos-1]                            // Extract x wave name
  746.     yWave = temp[pos+1, strlen(temp)]            // Extract y wave name
  747.     isXY = strlen(xWave) > 0
  748.     
  749.     xTempWaveName = MakeSampleTempWave(1, xWave, yWave)
  750.     yTempWaveName = MakeSampleTempWave(2, xWave, yWave)
  751.     
  752.     Make/O/N=6 pwMakeSampleData            // parameter wave for MakeSampleData
  753.     pwMakeSampleData[0] = gXMin
  754.     pwMakeSampleData[1] = gXMax
  755.     pwMakeSampleData[2] = offset
  756.     pwMakeSampleData[3] = amplitude
  757.     pwMakeSampleData[4] = gPercentXNoise
  758.     pwMakeSampleData[5] = gPercentYNoise
  759.     MakeSampleDataWaves(xTempWaveName, yTempWaveName, gNumPoints, pwMakeSampleData)
  760.     KillWaves/Z pwMakeSampleData
  761.  
  762.     Wave ytw = $yTempWaveName
  763.     Wave xtw = $xTempWaveName
  764.     
  765.     if (isXY)
  766.         if ((whichWave == 1) %| (whichWave == 3))
  767.             if (type == 1)                                    // Normal
  768.                 xtw += gnoise(amplitude)
  769.             endif
  770.             if (type == 2)                                    // Even
  771.                 xtw += enoise(amplitude)
  772.             endif
  773.         endif
  774.     endif
  775.     
  776.     if ((whichWave == 2) %| (whichWave == 3))
  777.         if (type == 1)                                        // Normal
  778.             ytw += gnoise(amplitude)
  779.         endif
  780.         if (type == 2)                                        // Even
  781.             ytw += enoise(amplitude)
  782.         endif
  783.     endif
  784.     
  785.     FinishMakeSampleData(mode, xWave, yWave, xTempWaveName, yTempWaveName)
  786.     CheckMakeSampleDataDisplay(xWave, yWave)        // display new data if desired
  787. End
  788.  
  789. Proc MakeSampleNoiseDialog(xWave, yWave, mode, offset, amplitude, type, whichWave)
  790.     String xWave                    // name of x wave or "" if waveform data
  791.     Prompt xWave, "X Wave", popup "_none_;_new_;" + WaveList("*", ";", "")
  792.     String yWave
  793.     Prompt yWave, "Y Wave", popup "_new_;" + WaveList("*", ";", "")
  794.     Variable mode = 1
  795.     Prompt mode, MakeSampleModePrompt(), popup "Set Output Wave;Add to Output Wave;Multiply Output Wave"
  796.     Variable offset = NumVarOrDefault("root:Packages:'Make Sample Data':gNoiseOffset", 0)
  797.     Prompt offset, "Offset"
  798.     Variable amplitude = NumVarOrDefault("root:Packages:'Make Sample Data':gNoiseAmplitude", 1)
  799.     Prompt amplitude, "Amplitude"
  800.     Variable type = NumVarOrDefault("root:Packages:'Make Sample Data':gNoiseType", 1)
  801.     Prompt type, "Noise type", popup "Normal;Even"
  802.     Variable whichWave = NumVarOrDefault("root:Packages:'Make Sample Data':gNoiseWhichWave", 2)
  803.     Prompt whichWave, "Add noise to", popup "X Wave;Y Wave;X and Y Waves"
  804.  
  805.     PauseUpdate; Silent 1
  806.     MakeSampleNoise(xWave, yWave, mode, offset, amplitude, type, whichWave)
  807. End
  808.